package com.example.rwq_test.designParttern.multiThread.guarded.suspension;

/**
 * TODO note
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2022/8/12
 */
public class TalkThread extends Thread {
    private final RequestQueue input;
    private final RequestQueue output;

    public TalkThread(RequestQueue input, RequestQueue output, String name) {
        super(name);
        this.input = input;
        this.output = output;
    }

    public void run() {
        System.out.println(Thread.currentThread().getName() + ":BEGIN");
        for (int i = 0; i < 20; i++) {
            Request request1 = input.getRequest();
            System.out.println(Thread.currentThread().getName() + " gets: " + request1);

            Request request2 = new Request(request1.getName() + "!");
            System.out.println(Thread.currentThread().getName() + " guts: " + request2);
            output.putRequest(request2);
        }
        System.out.println(Thread.currentThread().getName() + ":END");
    }
}
